<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.lmpop.trade.ti_teamorder.Ti_teamorderInfo"%>
<%@ page import="com.lmpop.frame.util.PageTools"%>
<%@ page import="com.lmpop.trade.tb_commpara.Tb_commparaInfo"%>
<%@page import="com.lmpop.trade.ts_category.*"%>
<%@ page import="com.lmpop.trade.ti_user.Ti_userInfo" %>
<%@page import="com.lmpop.trade.ti_finance.*" %>

		<%
		String _user_id = "", menu_id = "", menu_name = "";
		if (session.getAttribute("session_user_id") != null) {
			_user_id = session.getAttribute("session_user_id").toString();
		}
		String comm_user_id = "";
		if( session.getAttribute("session_user_id") != null ){
			comm_user_id = session.getAttribute("session_user_id").toString().trim();
		}
		String session_cust_id="";
		if(session.getAttribute("session_cust_id")!=null){
		  session_cust_id=session.getAttribute("session_cust_id").toString(); 
		}	
	
		String iStart = "0";
		int counter = 0;
		List list = null;
		int limit = 3;
		String pageString = null;
		String team_path = "/data/8diantuan/teambuy/";
		String teambuyurl = "";
		int listsize = 0;
		Hashtable nMap = new Hashtable();
		Ti_teamorderInfo ti_orderinfoInfo = new Ti_teamorderInfo();
		Tb_commparaInfo tb_commparaInfo = new Tb_commparaInfo(); 
		Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
		String _voucher_code = "", user_id = "", _enabled = "";
		String s_order_no = "", o_order_state = "";
		Map catMap = null;
		String selecttree = "";
		
		
		Ti_userInfo ti_userinfo = new Ti_userInfo();
		list = ti_userinfo.getComCodeByUserID(comm_user_id);
  	    Hashtable map = new Hashtable();
  	    if(list!=null && list.size()>0) map = (Hashtable)list.get(0);
		String comm_code="",comm_cust_id="";
  	    if(map.get("comm_code")!=null) comm_code = map.get("comm_code").toString();
	    if(map.get("reg_cust_id")!=null) comm_cust_id = map.get("reg_cust_id").toString();
	    Map ti_finance = new Hashtable();
		
		Ti_financeInfo ti_financeInfo = new Ti_financeInfo();
		if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
		Hashtable financeMap=new Hashtable();
		financeMap.put("cust_id",session_cust_id);
		financeMap.put("finance_type","1");
		financeMap.put("account_type","1");
		list = ti_financeInfo.getListByPk2(financeMap);
		
		Hashtable mapp = new Hashtable();
	  	if(list!=null && list.size()>0) mapp = (Hashtable)list.get(0);
		String cust_idd=session_cust_id,vmoney="0",use_vmoney="",frz_vmoney="",inter="",use_inter="",frz_inter="",remarkk="";
		String cust_name = "";
		if(mapp.get("cust_id")!=null) cust_idd = mapp.get("cust_id").toString();
		if(mapp.get("use_vmoney")!=null) vmoney = mapp.get("use_vmoney").toString();
%>
<%
		request.setCharacterEncoding("UTF-8");
		Map params = new Hashtable();
	  if(request.getParameter("s_order_no")!=null && !request.getParameter("s_order_no").equals(""))
	  {
	      s_order_no = request.getParameter("s_order_no"); 
	      params.put("order_no",s_order_no);
	  }
	  if(request.getParameter("o_order_state")!=null && !request.getParameter("o_order_state").equals(""))
	  {
	      o_order_state = request.getParameter("o_order_state"); 
	      params.put("order_state",o_order_state); 
	  }
  
		params.put("cust_id",session_cust_id);
		
		if(request.getParameter("iStart")!=null)
			 iStart = request.getParameter("iStart");

		counter = ti_orderinfoInfo.getTeamPerCountByObj(params);
		list = ti_orderinfoInfo.getTeamPerListByPage(params,Integer.parseInt(iStart),limit);

		
		//catMap= ts_categoryInfo.getCatClassMap("12");
		//selecttree=ts_categoryInfo.getCategoryTree("000000000000000","12","");	
		pageString = new PageTools().getGoogleToolsBar(counter,"/8diantuan_member.html?classtype=order&o_order_state="+o_order_state+"&s_order_no="+s_order_no+"&menu_id="+menu_id+"&zlpc=lucifer&iStart=",Integer.parseInt(iStart),limit);
		
		// pageString = new PageTools().getNongcunToolsBar(counter,"member_index.html?o_order_state="+o_order_state+"&s_order_no="+s_order_no+"&menu_id="+menu_id+"&zlpc=lucifer&iStart=",Integer.parseInt(iStart),limit);
	
	%>
	<table class="tablelist">
		<thead>
			<tr class="deal">

				<th >名称</th>

				<th >数量</th>
				 
				<th >总价</th>
				
			
				
				<th >交易状态</th>
				<th >操作</th>
            </tr>
       </thead>

		   <%           
						if(null != list && list.size() > 0){
						    listsize = list.size();
							String class_name="deal";
							for(int i=0;i < list.size()&& i<limit;i++){
									nMap = (Hashtable)list.get(i);
									String order_no="",_in_date="",type="",tuihuo="",state="",create_date="",price="",num="",total_price="",file_path="",order_state="",title="",info_id="",y_in_date="",t_in_date="";
									if(nMap.get("order_no")!=null) order_no = nMap.get("order_no").toString();
									if(nMap.get("num")!=null) num = nMap.get("num").toString();
									if(nMap.get("tuihuo")!=null) tuihuo = nMap.get("tuihuo").toString();
									if(nMap.get("type")!=null) type = nMap.get("type").toString();
									if(nMap.get("file_path")!=null) file_path = nMap.get("file_path").toString();
									if(nMap.get("in_date")!=null) _in_date = nMap.get("in_date").toString();
									if(_in_date.length()>19) y_in_date=_in_date.substring(0,19);
									if(nMap.get("create_date")!=null) create_date = nMap.get("create_date").toString();
									if(create_date.length()>19){
										 create_date=create_date.substring(0,19);	
										t_in_date = create_date.substring(0,10);
									}
									if(nMap.get("price")!=null) price = nMap.get("price").toString();
									if(nMap.get("total_price")!=null) total_price = nMap.get("total_price").toString();
									if(nMap.get("vmoney")!=null) {
										vmoney = nMap.get("vmoney").toString();
										if(vmoney!=null&&!vmoney.equals("")&&!vmoney.equals("0")){
											total_price=String.valueOf(Float.parseFloat(total_price)+Integer.parseInt(vmoney));
											String s=total_price.substring(total_price.indexOf("."),total_price.length());
											if(s.length()<3)
												total_price +="0";
										}
									}
									if(nMap.get("order_state")!=null) {
										order_state = nMap.get("order_state").toString();
										state=tb_commparaInfo.getSelectedValue("31",order_state);
									}
									
										java.text.DateFormat df2 = new java.text.SimpleDateFormat("yyyy-MM-dd");
										int s_date=0,e_date=0;
										Calendar s_cal = Calendar.getInstance();
										s_cal.setTime(df2.parse(_in_date.substring(0,10)));
										s_date = s_cal.get(Calendar.DAY_OF_MONTH);
										Calendar e_cal = Calendar.getInstance();
										e_cal.setTime(df2.parse((new Date().toLocaleString()).substring(0,10)));
										e_date = e_cal.get(Calendar.DAY_OF_MONTH);
									
									if(nMap.get("info_id")!=null) info_id = nMap.get("info_id").toString();
									if(nMap.get("title")!=null) title = nMap.get("title").toString();
									if (title.length()>50) title=title.substring(0,50);
									teambuyurl = team_path + t_in_date+"/"+info_id+".html";
									if(i!=0&&i/2!=1)
										out.print("<tr class='deal'>");
									else 
										out.print("<tr>");
			         %>
		  <!--  <tr>
				<td height="30" colspan="7" style="background:#EBEBEB;">	   
					订单编号:<%=order_no%>
					&nbsp;
					下单时间: <span style="color:#666666;"><%=y_in_date%></span>
				</td>
			</tr> -->
			
				<td height="60" width="30%" >
				
				<a href="<%=teambuyurl%>" target="_blank"><font class="goods_name<%=i%>"><%=title%></font></a>
				</td>  	
				<td ><%=num%></td>
				<td ><%=total_price%></td>
				
				<td >
					<%=state%>

				</td>
				<td >
					<% if(order_state.equals("0")){%>
						<a href="javascript:pay('<%=order_no%>','<%=total_price%>','0','EMS','<%=title%>');" >付款</a>					
					<%}else if(order_state.equals("1")&&type.equals("1")&&(e_date-s_date)>=7){%><!--  -->
				    	<a href="javascript:updateState('<%=order_no %>','55','a_1',<%=i %>)" id="a_1">退款</a>  
				  	<%}else if(order_state.equals("2")){%>
				    	<a href="javascript:updateState('<%=order_no %>','3','a_1',<%=i %>)" id="a_1">交易成功</a>  
				  	<%}else if (order_state.equals("3")&&type.equals("2")&&tuihuo.equals("1")) {%>             	
                  		<a href="javascript:updateState('<%=order_no %>','5','a_3',<%=i %>)" id="a_3">退货</a>
					<%}%>
					<a href='#' onclick="orderFile('<%=order_no%>')">查看</a>
				</td>
            </tr>
			<%
					}
				}
			%>
       </table>
	<div style="float:right; margin-top:10px;">   
<%=pageString%>  
</div>
